package br.unisinos.projetotcc.pesquisa;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;

public class TesteBCEL2 {

	public static void main(String[] args) throws IOException {
		
	/*	ClassParser p = new ClassParser("C:\\Users\\MARVAN\\Desktop\\teste\\Teste.class");
		JavaClass jc = p.parse();
		ClassGen cg = new org.apache.bcel.generic.ClassGen(jc);
		ConstantPoolGen cp = new ConstantPoolGen(jc.getConstantPool());
		
		InstructionFactory factory = new InstructionFactory(cg);*/
		
		File f = new File("C:\\Users\\MARVAN\\Desktop\\teste\\Teste.class");

		ClassLoader loader = new URLClassLoader(new URL[] { f.toURI().toURL() });
		
		    try {
		        String filename = f.getName();
		        // Remove the .class extension
		        Class<?> cls = loader.loadClass("C:\\Users\\MARVAN\\Desktop\\teste\\Teste.class");
		        
		        Method[] methods = cls.getMethods();
		        
		        System.out.println(methods[0].invoke(null, (Object)args));
		        
//		        System.out.println(methods[0].invoke(""));
		        
		        // Do something with the class
		    } catch (Exception ex) {
		    }
		}
		
	
}
